package com.itheima.behaviour.mq;

import com.alibaba.fastjson.JSON;
import com.itheima.behaviour.dto.FollowBehaviorDto;
import com.itheima.behaviour.pojo.ApFollowBehavior;
import com.itheima.behaviour.service.ApFollowBehaviorService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @Author：shenkunlin
 * @date： 2021/8/30 11:18
 * @Description：
 ***/
@Component
public class FollowListener {

    @Autowired
    private ApFollowBehaviorService apFollowBehaviorService;

    /***
     * 收消息->关注行为
     */
    @KafkaListener(topics = "followQueue",groupId = "followGroup")
    public void followInfo(ConsumerRecord<?,?> record){
        //获取消息
        String message = record.value().toString();
        //dto
        FollowBehaviorDto followBehaviorDto = JSON.parseObject(message, FollowBehaviorDto.class);
        System.out.println("--->监听到的消息："+followBehaviorDto);
        apFollowBehaviorService.addFollowBehavior(followBehaviorDto);
    }
}
